// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({    env: "dzc-aapp-0g1mx02g41e97626", }) // 使用当前云环境
const db = cloud.database()
const _ = db.command

// 云函数入口函数
exports.main = async (event, context) => {
    const { momentId, commentUser, commentContent } = event
    try {
        const newComment = {
            commentUser,
            commentContent
        }
        const res = await db.collection('moments').doc(momentId).update({
            data: {
                comments: _.push(newComment)
            }
        })
        return res
    } catch (err) {
        console.error('评论提交失败:', err)
        return {
            errMsg: '评论提交失败',
            err
        }
    }
}    